"use strict";
/* Controllers */
app.controller("taskRelationListController", ['$scope', '$location', '$rootScope', '$routeParams', 'taskRelationListService', function ($scope, $location, $rootScope, $routeParams, taskRelationListService) {

    var vm = $scope.vm;

    vm.p = {};
    vm.result = {};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listTaskRelation = function () {
        var vm = $scope.vm;
        var params = $scope.vm.p;
        $('#list_table').bootstrapTable('showLoading');
        $("#refreshTable").addClass('disabled');
        var procFn = function (response) {
            var data = response.data;
            if (data == null) {
                return;
            }
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
            $('#list_table').bootstrapTable('hideLoading');
            $("#refreshTable").removeClass('disabled');
        };
        taskRelationListService.listTaskRelation(params, procFn, errorFn);
    };

    $("#refreshTable").click(function () {
        $('#list_table').bootstrapTable('refresh');
        $scope.listTaskRelation()
    });

    $("#showScore").click(function () {
        var vm = $scope.vm;
        var params = $scope.vm.p;
        if(!params.task){
            return;
        }
        var procFn = function (response) {
            var data = response.data;
            if (data == null) {
                return;
            }
            $("#securityScore").text(data.securityScore);
            $("#importantScore").text(data.importantScore);
            var securityTxt = "";
            if(data.securityDetailList){
                for(var i in data.securityDetailList){
                    securityTxt += data.securityDetailList[i] + "\n";
                }
                $("#securityDetail").text(securityTxt);
            }
            /*if(data.importantDetailList){
                var importantTxt = "";
                for(var i in data.importantDetailList){
                    importantTxt += data.importantDetailList[i] + "\n";
                }
                $("#importantDetail").text(importantTxt);
            }*/
        };
        taskRelationListService.getTaskScore(params, procFn, errorFn);
        $("#myModal").modal('show');
    });

    $scope.initializeController = function () {
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [100, 300, 500], pageSize: 100
        });
        //$scope.listYarnApplication();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('taskRelationListService', ['ajaxService', function (ajaxService) {

    this.listTaskRelation = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/task_info/findRelateTaskByTask.do", successFunction, errorFunction);
    };

    this.getTaskScore = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/task_info/getTaskScore.do", successFunction, errorFunction);
    };

}]);

